﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Model
{
	public class CompanyRequestContext : BaseContext
	{
		Company company = null;
		public override void SetContext(object context)
		{
			base.SetContext(context);

			if (context is Company)
			{
				company = context as Company;
			}
		}

		public override object GetContext()
		{
			if (company == null)
				return string.Empty;

			startDocument();

			Write(writer);

			return endDocument();
		}

		public void Write(XmlWriter writer)
		{
			writer.WriteStartElement("Company");


			writer.WriteAttributeString("id", company.Id);
			writer.WriteAttributeString("name", company.Name);
			writer.WriteAttributeString("address", company.Address);
			writer.WriteAttributeString("city", company.City);
			writer.WriteAttributeString("state", company.State);
			writer.WriteAttributeString("zip", company.Zip);
			writer.WriteAttributeString("country", company.Country);
			writer.WriteAttributeString("phone", company.Phone);
			writer.WriteAttributeString("currency", company.Currency);

			InitExtendedAttributes(writer, company);
			InitExtendedElements(writer, company);



			if (company.BillingInfo != null)
			{
				BillingInfoRequestContext billingRequestContext = new BillingInfoRequestContext();
				billingRequestContext.SetContext(company.BillingInfo);
				billingRequestContext.Write(writer);
			}

			if ((company.Contacts != null) && (company.Contacts.Length > 0))
			{
				ContactRequestContext contactrequestcontext = new ContactRequestContext();
				contactrequestcontext.SetContext(company.Contacts);
				contactrequestcontext.Write(writer);
			}
			writer.WriteEndElement();
		}
	}
}
